<?php
class SitemapAction extends Action {
    
    //中文SITEMAP (如百度)
    //用途：显示
    public function cn(){
    	$site = "http://".$_SERVER["HTTP_HOST"];
    	 
    	$str = '<?xml version="1.0" encoding="UTF-8"?>
    			<urlset>';
    	 
    	//首页
    	$url = $site."/";
    	$str .= CommonUtil::create_baidu_site_node($url, time(), "always", 1.0);
    	
    	//$DYNAMIC_MODULE列表页 & 封面页
    	$list = CatalogHelper::getList();
    	foreach ($list as $catalog){
    		if($catalog["catalog_type"] == CatalogType::$DYNAMIC_MODULE || $catalog["catalog_type"] == CatalogType::$FM_PAGE){
    			$url = $site.LinkUtil::getCataLink($catalog);
    			$str .= CommonUtil::create_baidu_site_node($url, time(), "daily", 0.8);
    		}
    	}
    	//$DYNAMIC_MODULE其他页
    	$list = CatalogHelper::getList();
    	foreach ($list as $catalog){
    		if($catalog["catalog_type"] != CatalogType::$DYNAMIC_MODULE && $catalog["catalog_type"] != CatalogType::$FM_PAGE){
    			$url = $site.LinkUtil::getCataLink($catalog);
    			$str .= CommonUtil::create_baidu_site_node($url, time(), "weekly", 0.6);
    		}
    	}
    	//$DYNAMIC_MODULE列表页下的内页
    	$list = DynamicModuleHelper::getList();
    	foreach ($list as $dynamicModule){
    		if($catalog["catalog_type"] == CatalogType::$DYNAMIC_MODULE){
	    		$tableName = C("DB_PREFIX").$dynamicModule["table_name"];
	    		$sql = "SELECT * FROM {$tableName} ORDER BY id DESC LIMIT 20";
    			$dlist = ArticleHelper::queryList($sql);
    			foreach ($dlist as $d){
    				$url = $site.LinkUtil::getLink($d["id"], $d["catalog_id"]);
    				$str .= CommonUtil::create_baidu_site_node($url, time(), "weekly", 0.6);
    			}
    		}
    	}
    	 
    	$str .= '</urlset>';
    	$this->show($str, 'utf-8', 'application/xml');
    }
    
    //国际SITEMAP （如：谷歌）
    //用途：显示
	public function eng(){
    	$site = "http://".$_SERVER["HTTP_HOST"];
    	 
    	$str = '<?xml version="1.0" encoding="UTF-8"?>
    			<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
    	 
    	//首页
    	$url = $site."/";
    	$str .= CommonUtil::create_google_site_node($url, time(), "always", 1.0);
    	
    	//$DYNAMIC_MODULE列表页 & 封面页
    	$list = CatalogHelper::getList();
    	foreach ($list as $catalog){
    		if($catalog["catalog_type"] == CatalogType::$DYNAMIC_MODULE || $catalog["catalog_type"] == CatalogType::$FM_PAGE){
    			$url = $site.LinkUtil::getCataLink($catalog);
    			$str .= CommonUtil::create_google_site_node($url, time(), "daily", 0.8);
    		}
    	}
    	//$DYNAMIC_MODULE其他页
    	$list = CatalogHelper::getList();
    	foreach ($list as $catalog){
    		if($catalog["catalog_type"] != CatalogType::$DYNAMIC_MODULE && $catalog["catalog_type"] != CatalogType::$FM_PAGE){
    			$url = $site.LinkUtil::getCataLink($catalog);
    			$str .= CommonUtil::create_google_site_node($url, time(), "weekly", 0.6);
    		}
    	}
    	//$DYNAMIC_MODULE列表页下的内页
    	$list = DynamicModuleHelper::getList();
    	foreach ($list as $dynamicModule){
    		if($catalog["catalog_type"] == CatalogType::$DYNAMIC_MODULE){
	    		$tableName = C("DB_PREFIX").$dynamicModule["table_name"];
	    		$sql = "SELECT * FROM {$tableName} ORDER BY id DESC LIMIT 20";
    			$dlist = ArticleHelper::queryList($sql);
    			foreach ($dlist as $d){
    				$url = $site.LinkUtil::getLink($d["id"], $d["catalog_id"]);
    				$str .= CommonUtil::create_google_site_node($url, time(), "weekly", 0.6);
    			}
    		}
    	}
    	 
    	$str .= '</urlset>';
    	$this->show($str, 'utf-8', 'application/xml');
    }
    
    
    
}